﻿//UserPop.js
function UserPop_Info(map)
{
    this.map=map;
    this.popData=
    {
    };
};
UserPop_Info.prototype=
{
    createUserPopById:function(id)
    {
        var arr=this.popData[id];
        if(!arr) return;
        for(var i=0;i<arr.length;i++)
        {
            this.createUserPop(arr[i]);
        }
    }
    ,getIdStr:function(e)
    {
        var id=this.getUPIdStr(e.type.split('_')[0])+e.id;
        return id;
    }
    ,getCfg:function(e,param)
    {
        if(!e.type) e.type='yp_10';
        var classNames=['red_div','green_div','blue_div'];
        var classIndex=
        {
            yp_0:2,yp_1:2,yp_2:1,yp_3:2,yp_4:0,yp_5:1,yp_6:2,yp_7:2,yp_8:0,yp_9:0,yp_10:0,et_1:0,bs_1:2,bs_2:0,vr_1:2
        };
        var cfg=
        {
        };
        cfg.global=false;
        cfg.display=false;
        cfg.className=classNames[classIndex[e.type]];
        cfg.type=e.type.split('_')[0];
        cfg.idStr=this.getIdStr(e);
        cfg.img=e.type+'.gif';
        cfg.args='';
        if(param&&param.img)
        {
            var ci=classIndex[param.img];
            if(ci||ci==0)cfg.className=classNames[ci];
        }
        Object.extend(cfg,param,true);
        return cfg;
    }
    ,createUserPop:function(e,param)
    {
        //alert('createUserPop');
        var cfg=this.getCfg(e,param);
        var elm;
        if(this.map.objs['info'].length==0)
        {
            elm=document.createElement('div');
            elm.style.cursor='pointer';
            elm._node='info';
            elm.onclick=this.userPop_click.bindAsEventListener(this);
            elm.onmouseover=function(evt)
            {
                var src=evt.srcElement||evt.target;
                src=this.getObj(src,'info');
                if(src._dis) return;
                src.parentNode.style.zIndex=100;
                src.style.zIndex=100;
                var obj=$('div'+src._id);
                if(obj) obj.style.display='';
            }
            .bindAsEventListener(this);
            elm.onmouseout=function(evt)
            {
                var src=evt.srcElement||evt.target;
                src=this.getObj(src,'info');
                if(src._dis) return;
                src.parentNode.style.zIndex=5;
                src.style.zIndex=5;
                var obj=$('div'+src._id);
                if(obj) obj.style.display='none';
            }
            .bindAsEventListener(this);
        }
        else
        {
            elm=this.map.objs['info'].pop();
        }
        elm._id=e.id;
        elm._name=e.name;
        elm._x=e.x;
        elm._y=e.y;
        elm._t=cfg.type;
        elm._args=cfg.args;
        var disStr='';
        if(cfg.display)
        {
            elm._dis=1;
        }
        else
        {
            elm._dis=0;
            disStr='display:none';
        }
        var str='';
        if(this.type==1&&e.type=='-2')str='id="bus'+e.id+'" _id='+e.id+' _name="'+e.name+'" _x='+e.x+' _y='+e.y+' title="'+e.name+'"';
        elm.innerHTML='<img src="'+this.map.apiPath+'/images/skin2/icon/'+cfg.img+'" '+str+' style="float:left;" width="27" height="37" border="0"><div id="div'+e.id+'" style="position:absolute;left:28px;white-space:nowrap;'+disStr+'" class="'+cfg.className+'"> <a href="#" class="red" title="'+national.getStr('Common','ClickHere','点击查看详细信息')+'">'+e.name +'</a></div>';
        if(!cfg.global)this.map.createPopT(cfg.idStr,elm,e.x,e.y,15,36,5,this.infoLoadLevel);
        else this.map.createPop(cfg.idStr,elm,e.x,e.y,15,36,5);
        return cfg.idStr;
    }
    ,userPop_click:function(evt)
    {
        var src=evt.srcElement||evt.target;
        src=this.getObj(src,'info');
        if(this.moved>0)return;
        if(src._t=='et') this.map.showOCInfo(src._x,src._y,src._id);
        else if(src._t=='bs') this.showStationBlog(src._id,src._name,src._x,src._y);
        else if(src._t=='vr')
        {
            var arr=src._args.split(',');
            if(arr.length<3) return false;
            this.map.openwin(arr[0],src._id,arr[1],arr[2]);
        }
        else this.map.showOCInfo(src._x,src._y,0,src._id,true);
        return false;
    }
    ,getUPIdStr:function(type)
    {
        if(type=='yp') return 'up_unit';
        else if(type=='et') return 'up_entity';
        else if(type=='vr') return 'up_vr';
        else if(type=='bs') return 'busStation';
        else return 'search';
    }
    ,getObj:function(obj,type)
    {
        if(!obj) return null;
        if(obj._node==type) return obj;
        while(obj.parentNode&&obj.parentNode!=document.body)
        {
            obj=obj.parentNode;
            if(obj._node==type) return obj;
        }
        return null;
    }
//    ,
//    showStationBlog:function(id,name,x,y)
//    {
//        if(this.map.moved>3)return;
//        var sx=180*Math.pow(2,this.map.Zoom-1);
//        var sy=20*Math.pow(2,this.map.Zoom-1);
//        var htmlStr='<div style="position:absolute;left:-67px;top:153px;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="24px" height="24px"> <param name="movie" value="/images/flash/kkk.swf"> <param name="quality" value="high"> <param name="wmode" value="transparent"> <embed src="api/images/kkk.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="24px" height="24px"></embed></object></div><div style="position:absolute;left:-53px;top:129px;"><img src="images/map/point2.gif"></div><img border="0" style="position:absolute;left:310px;top:6px;cursor:pointer" src="/images/map/close.gif" onclick="mapApi.removePop(\'pop_bus\')"><div id="Layer1"><div style="background:#fff;padding:1 0 0 1;width:332;height:230;"><div style="height:100%; width:100%; "><div style="background:#fff;height:100%; width:100%;"><iframe src="'+this.map.blogPath+'busstation.jspa?locale='+this.map.locale+'&id={@ID}" height="100%" width="100%" frameborder="0" scrolling="no" ></iframe></div></div></div></div>';
//        htmlStr=htmlStr.replace('{@ID}',id);
//        this.map.AreaUnitInfo=
//        {
//        };
//        this.map.AreaUnitInfo.AreaID=id;
//        this.map.AreaUnitInfo.AreaName=name;
//        this.map.AreaUnitInfo.x=x;
//        this.map.AreaUnitInfo.y=y;
//        this.map.AreaUnitInfo.type=3;
//        this.map.removePop('pop_bus');
//        this.map.go2xyS(parseInt(x)+sx,parseInt(y)-sy);
//        this.map.createPop('pop_bus',htmlStr,x,y,-55,165,7,this.map.infoLoadLevel);
//    }
};